﻿namespace Codeplex.Controls.Sample.Adorner
{
    using System.Windows;
    using System.Windows.Controls;
    using Controls;

    public partial class MainPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = (Button)sender;

            var p = button.Tag as Adorner;

            if (p != null)
            {
                p.Dispose();
                button.Tag = null;
            }
            else
            {
                var adorner = new Adorner(button)
                {
                    Template = Application.Current.Resources["MyAdornerControlTemplate"] as ControlTemplate
                };
                button.Tag = adorner;
            }
        }
    }
}